package com.heima.controller;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.service.MaterialService;
import io.minio.errors.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * @author chenshan
 */
@RestController
@RequestMapping("/api/v1/material/")
public class MaterialController {
    @Autowired
    private MaterialService materialService;

    /**
     * 自媒体端文件上传
     * @param multipartFile 文件
     * @return ResponseResult
     */
    @PostMapping("upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile) throws IOException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, ServerException, InternalException, XmlParserException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException {
        return materialService.uploadPicture(multipartFile);
    }

    /**
     * 当前登录用户的素材的分页查询
     * @param materialDto 是否收藏和分页条件
     * @return ResponseResult 分页结果
     */
    @PostMapping("list")
    public PageResponseResult materialList(@RequestBody WmMaterialDto materialDto) {
        return materialService.materialList(materialDto);
    }
}
